package com.dyrj.question.controller;

import com.dyrj.pig.result.JsonResult;
import com.dyrj.question.dao.PDwMapper;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.RequestMapping;
import com.dyrj.vo.PageResultMsg;
import com.dyrj.vo.ResultMsg;
import com.dyrj.question.service.IPDwService;
import com.dyrj.question.bean.PDw;
import java.util.List;

import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author admin
 * @since 2021-05-12
 */
@Controller
@RequestMapping("/question/p-dw")
public class PDwController {

    @Resource
    private IPDwService service;
    @Resource
    private PDwMapper pDwMapper;
    @GetMapping("/index")
    @RequiresPermissions("question:p-dw:index")
    public String index(ModelMap map) {
    return "question/index_p-dw";
    }

    /**
    * @Title: table
    * @Description: (表格数据) 列表
    * @return PageInfo<PDw>    返回类型
    */
    @GetMapping("/table")
    @ResponseBody
    @RequiresPermissions("question:p-dw:index")
    public PageResultMsg table(PDw record) {
        return service.table(record);
    }
    @GetMapping("/table1")
    @ResponseBody
    @RequiresPermissions("question:p-dw:index")
    public PageResultMsg table1(PDw record) {
        return service.table1(record);
    }
    /**
    * @Title: add
    * @Description: (新增)
    * @param record
    * @return ResultMsg    返回类型
    */
    @PostMapping("/")
    @ResponseBody
    @RequiresPermissions("question:p-dw:add")
    public ResultMsg add(PDw record) {
        return service.add(record);
    }
    @GetMapping("/getList")
    @ResponseBody
    public JsonResult<List> getZslbList(){
        JsonResult<List> result = new JsonResult<>();
        List<PDw> list = pDwMapper.selectList(null);
        for(int i=0;i<list.size()-1;i++){
            for  ( int  j  =  list.size()  -   1 ; j  >  i; j -- )  {
                if  (list.get(j).getSjdwmc().equals(list.get(i).getSjdwmc()))  {
                    list.remove(j);
                }
            }
        }
        result.setData(list);
        return result;
    }
    /**
    * @Title: info
    * @Description: (详情)
    * @param id
    * @return PDw    返回类型
    */
    @GetMapping("/{id}")
    @ResponseBody
    @RequiresPermissions("question:p-dw:info")
    public PDw info(@PathVariable String id) {
        return service.info(id);
    }

    /**
    * @Title: update
    * @Description: (更新)
    * @param record
    * @return ResultMsg    返回类型
    */
    @PutMapping("/")
    @ResponseBody
    @RequiresPermissions("question:p-dw:edit")
    public ResultMsg update(PDw record) {
        return service.update(record);
    }

    /**
    * @Title: delete
    * @Description: (删除)
    * @param id
    * @return ResultMsg    返回类型
    */
    @DeleteMapping("/{id}")
    @ResponseBody
    @RequiresPermissions("question:p-dw:delete")
    public ResultMsg delete(@PathVariable String id) {
        return service.delete(id);
    }


}
